package com.itheima.controller;

import com.itheima.Service.ClazzService;
import com.itheima.entity.*;
import com.itheima.entity.Clazz;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : 班级 Controller层
 * @description :
 * @date : 2023/6/14 16:02
 */
@RestController
public class ClazzController {
    private static final org.slf4j.Logger log = LoggerFactory.getLogger(DeptController.class);

    @Autowired
    private  ClazzService clazzService;

    /**
     * 查询所有班级
     * @return
     */
    @GetMapping("/clazzs/list")
    public Result getAll() {
        log.info("获取班级列表");
        List<Clazz> clazzs = clazzService.list();
        return Result.success(clazzs);
    }

    @GetMapping("/clazzs")
    public Result Page(ClazzQueryParam param) {
        log.info("获取班级列表：{}", param);
        PageBean pagebean = clazzService.page(param);
        return Result.success(pagebean);
    }

    @DeleteMapping("/clazzs/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除班级：{}",id);
        clazzService.delete(id);
        return Result.success();
    }

    @PostMapping("/clazzs")
    public Result add(@RequestBody Clazz clazz) {
        log.info("添加班级：{}",clazz);
        clazzService.add(clazz);
        return Result.success();
    }

    @GetMapping("/clazzs/{id}")
    public Result getByClzzID(@PathVariable Integer id) {
        log.info("获取班级：{}",id);
        Clazz clazz = clazzService.getById(id);
        return Result.success(clazz);
    }

    @PutMapping("/clazzs")
    public Result update(@RequestBody Clazz clazz) {
        log.info("修改班级：{}",clazz);
        clazzService.update(clazz);
        return Result.success();
    }
}
